package com.four.peoplemanage.leave.controller;

import com.four.peoplemanage.common.bean.ResponseData;
import com.four.peoplemanage.common.controller.BaseController;
import com.four.peoplemanage.leave.entity.Leave;
import com.four.peoplemanage.leave.service.LeaveService;
import com.four.peoplemanage.overtime.entity.Overtime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/leave")
public class LeaveController extends BaseController {
    @Autowired
    LeaveService leaveService;

    //申请请假
    @PostMapping("/insert")
    public ResponseData<Boolean> insertLeave(Leave leave){
        return returnBoolean(leaveService.insert(leave));
    }

    //分页
    @GetMapping("/getAll")
    public ResponseData<Object>  getAll(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize") int pageSize,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "leave_type",required = false) String leave_type,
            @RequestParam(value = "leave_status",required = false) String leave_status


    ){
        return returnObject(leaveService.getAllLeave(pageNum, pageSize, name, leave_type,leave_status));

    }
    //分页
    @GetMapping("/getone")
    public ResponseData<Object>  getOne(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize") int pageSize,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "leave_type",required = false) String leave_type,
            @RequestParam(value = "leave_status",required = false) String leave_status,
            @RequestParam(value = "information_id",required = false) int information_id


    ){
        return returnObject(leaveService.getPageLeave(pageNum, pageSize, name, leave_type,information_id,leave_status));

    }

    //更新状态可撤销
    @PutMapping("/updateS")
    public  ResponseData<Boolean> updateS(@RequestBody Leave leave){
        return returnBoolean(leaveService.updateStatus(leave));
    }
    //通过
    @PutMapping("/receive")
    public  ResponseData<Boolean> receive(@RequestBody Leave leave){
        return returnBoolean(leaveService.updateSuccess(leave));
    }
    //驳回
    @PutMapping("/reject")
    public  ResponseData<Boolean> reject(@RequestBody Leave leave){
        return returnBoolean(leaveService.updateFail(leave));
    }

    //编辑
    @PutMapping("/update")
    public ResponseData<Boolean> update(@RequestBody Leave leave){
        return returnBoolean(leaveService.updateLeave(leave));
    }

}
